# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@作者 杨阳
@时间 2018-06-01
@说明 第三方框架初始化工具类
@注意事项
"""

from flask import Flask

import settings
from util.ThreadPluginsInitUtil import cors
from util.ThreadPluginsInitUtil import db
from util.ThreadPluginsInitUtil import login_manager


def create_app(config_name):
    app = Flask(config_name)
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = settings.SQLALCHEMY_TRACK_MODIFICATIONS
    app.config['DEBUG'] = settings.DEBUG
    app.config['SQLALCHEMY_ECHO'] = settings.SQLALCHEMY_ECHO
    app.config['SECRET_KEY'] = settings.SECRET_KEY
    app.config['SERVER_NAME'] = settings.SERVER_NAME

    login_manager.init_app(app)
    db.init_app(app)
    cors.init_app(app, supports_credentials=True)

    return app
